package com.cb.controller;

import com.cb.pojo.Film;
import com.cb.config.CorsConfig;
import com.cb.service.FilmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.logging.Logger;

@RestController
@RequestMapping("/administratorfilm")
@Api(value = "管理员操作电影", description = "管理员操作电影")
public class  FilmController {

    @Autowired
    FilmService filmService;
    @Autowired
    CorsConfig corsConfig;

    /**
     * 添加电影功能
     * @param film
     * @param request
     * @return
     * @throws IOException
     * @throws SQLException
     */
    @PostMapping("/insertfilm")
    @ResponseBody
    @ApiOperation(value = "添加电影功能", notes = "添加电影功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "film", value = "影片对象"),
    })
    public String filmInsert(Film film, HttpServletRequest request) throws IOException, SQLException {
        return filmService.filmInsert(film,request);
    }

    /**
     * 查看自己影院当前所有电影
     * @param json
     * @return
     */
    @PostMapping("/selectfilm")
    @ApiOperation(value = "查看自己影院当前所有电影", notes = "查看自己影院当前所有电影")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyid", value = "影院id"),
    })
    public String selectFilm(@RequestBody HashMap json, HttpServletRequest request) {
        return filmService.selectFilm(json,request);
    }

    /**
     * 根据国家，时间，类型筛选影片
     * @param json
     * @return
     */
    @PostMapping("/selectFilmother")
    @ApiOperation(value = "根据国家，时间，类型筛选影片", notes = "根据国家，时间，类型筛选影片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "countries", value = "国家"),
            @ApiImplicitParam(name = "type", value = "类型"),
            @ApiImplicitParam(name = "markettime", value = "上映时间"),
    })
    public String selectFilmother(@RequestBody HashMap json, HttpServletRequest request){
        return filmService.selectFilmother(json,request);
    }


    /**
     * 删除影片
     * @param json
     * @return
     */
    @PostMapping("/deletefilm")
    @ResponseBody
    @ApiOperation(value = "删除影片", notes = "删除影片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "影片编号"),
            @ApiImplicitParam(name = "yyid", value = "影院编号")
    })
    public String deletefilm(@RequestBody HashMap json, HttpServletRequest request){
        return filmService.deletefilm(json,request);
    }

    /**
     * 查看影院下面电影详情
     * @param json
     * @return
     */
    @PostMapping("/selectfilmdetial")
    @ResponseBody
    @ApiOperation(value = "删除影片", notes = "删除影片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyid", value = "影院编号"),
            @ApiImplicitParam(name = "ypid", value = "影片编号")
    })
    public String selectqXQByyyyp(@RequestBody HashMap json, HttpServletRequest request) throws ParseException {
        return filmService.yyidSelectsiYyid(json,request);
    }

}
